require "Common/define"
require "Logic/Config"
require "Common/functions"

---@class UIEquipInfo:UIComponentInterface
UIEquipInfo = {}
HelperFunc.SetUIEnv(UIEquipInfo)
local this = UIEquipInfo;

this.LuaBehaviour = nil;
this.transform = nil;
this.gameObject = nil;

this.IconBg = nil;
this.Icon = nil;
this.equipName = nil;
this.refine = nil;
this.level = nil;
this.part = nil;
this.attack = nil;
this.attrlist = nil;
this.suit = nil;
this.suitName = nil;
this.packageResult1 = nil;
this.result_num1 = nil;
this.packageResult2 = nil;
this.result_num2 = nil;
this.result_tips1 = nil;
this.result_tips2 = nil;
this.equipDes = nil;

this.twoSuit = nil
this.fourSuit = nil

this.twoSuitDataList = nil
this.fourSuitDataList = nil

this.bgclose = nil;
this.btn_refine = nil;
this.btn_unload = nil;
this.btn_replace = nil;
this.btn_switch = nil;
this.btn_buy = nil;
this.breakctrl = nil
this.btn_upGrade = nil

this.hasInit = false;
this.curShowHeroData = nil;
this.curEquipData = nil;
this.partID = 0;
this.baseAttrData = nil;
this.equipInfo = nil

this.panelType = nil;
this.frame = nil;
this.panelEnum = {
    UICharactorInfoHeroEquip = 0,
    Bag = 1,
    shop = 2,
}

--- 价格显示
this.nodeCost = nil
this.nodeCostIcon = nil
this.nodeCostTxt = nil

this.ShowEnterType = nil
this.func = nil;

function UIEquipInfo.Init(herodata, equipdata, Type, func)
    curShowHeroData = herodata;

    if equipdata == nil then
        curEquipData = nil;
    elseif equipdata.itemId then
        curEquipData = logicMgr.EquipManager.getEquipbyId(equipdata.itemId);
    end

    if Type ~= nil then
        panelType = Type;
        if Type == panelEnum.shop then
            curEquipData = equipdata;
        end
    else
        panelType = nil;
        curEquipData = equipdata;
    end

    this.ShowEnterType = ShowType
    this.func = func;

    print(equipdata.itemModelId)
    local name, packageName = getUIName(PanelNames.UIEquipInfo);
    panelMgr:ShowUI(name, packageName, this.onCreate, Config.useLocalUI);
end

function UIEquipInfo.onCreate(obj)
    gameObject = obj;

    if not hasInit then
        hasInit = true;
        this.equipItem = obj:GetChild("equip")
        equipName = obj:GetChild("equipName");
        level = obj:GetChild("level");
        part = obj:GetChild("title");
        partIcon = obj:GetChild("n90"):GetChild("icon")
        attack = obj:GetChild("attack")
        local gList = obj:GetChild("equipInfo")
        gList:RemoveChildrenToPool()
        local itemObj = gList:AddItemFromPool()
        this.attrlist = itemObj:GetChild("attrlist")
        this.attrlist.itemRenderer = this.RenderAttr

        this.suit = itemObj:GetChild("suit")
        suitName = suit:GetChild("packageName");
        suitName2 = suit:GetChild("packageName2")
        suitIcon = suit:GetChild("n11"):GetChild("icon")
        suitIcon2 = suit:GetChild("n19"):GetChild("icon")
        packageResult1 = suit:GetChild("packageResult1");
        result_num1 = suit:GetChild("num1");

        this.twoList = suit:GetChild("List_Des1")
        this.twoList.itemRenderer = this.RenderTwoSuitAttr

        this.fourList = suit:GetChild("List_Des2")
        this.fourList.itemRenderer = this.RenderTwoSuitAttr2
        --todo

        packageResult2 = suit:GetChild("packageResult2");
        result_num2 = suit:GetChild("num2");
        --result_tips1 = suit:GetChild("tips1"):GetChild("text");
        --result_tips2 = suit:GetChild("tips2"):GetChild("text");
        equipDes = itemObj:GetChild("equipDes");
        this.btnSuitTipInfo = suit:GetChild("n16")
        this.ctrlSuit = itemObj:GetController("hasSuit")


        bgclose = obj:GetChild("bgclose");
        btn_refine = obj:GetChild("btn_refine");
        btn_unload = obj:GetChild("btn_unload");
        btn_switch = obj:GetChild("btn_switch");
        btn_replace = obj:GetChild("btn_replace");
        btn_buy = obj:GetChild("btn_buy");
        nodeCost = obj:GetChild("cost")
        nodeCostIcon = nodeCost:GetChild("Image");
        nodeCostTxt = nodeCost:GetChild("num");
        this.breakctrl = obj:GetController("ifBreak")
        this.btn_upGrade = obj:GetChild("btn_break")
        this.ctrlSuitInfo = obj:GetController("suitInfo")
        this.ctrlStateEquip = obj:GetController("state")
        this.suitTipText = obj:GetChild("infoType")
        this.recommendList = obj:GetChild("recommendHero"):GetChild("list")
        this.recommend = obj:GetController("recommend")
    end
    this.ctrlSuitInfo.selectedIndex = 0
    this.recommend.selectedIndex = 0
    local _bgBottomIndex = 0
    if this.curEquipData and this.panelType == this.panelEnum.Bag then
        _bgBottomIndex = 1
    end
    obj:GetController("bgBottom"):SetSelectedIndex(_bgBottomIndex)
    this.addEvent();

    this.initUI()
end

function UIEquipInfo.initEquipRankData(obj,equipQuality)
    local quality = obj
    local qualityFrame = quality:GetChild("frame")
    local qualityIcon = quality:GetChild("icon")
    local qualityNumIcon = quality:GetChild("numIcon")
    local staegeController = quality:GetController("jinjie")
    local maxController = quality:GetController("LR");
    local config = G.dataTable.t_iconframe[tostring(equipQuality)]
    local isFrame = config.f_Ornaments ~= ""
    qualityFrame.visible = isFrame
    local atlas = "ui://CharactorUI/"
    if isFrame then
        qualityFrame.url = atlas..config.f_QualityOrnaments
    end
    if config.f_QualityText~= "" then
        qualityIcon.url = atlas..config.f_QualityText
        staegeController.selectedIndex = 1;
    else
        staegeController.selectedIndex = 0;
    end
    qualityNumIcon.url = atlas..config.f_QualityIcon
    if config.f_Id > 10 then
        staegeController.selectedIndex = 0;
        maxController.selectedIndex = equipQuality-10;
    else
        maxController.selectedIndex = 0;
    end
   
end
function UIEquipInfo.addEvent()
    bgclose.onClick:Add(this.clickClose);
    btn_refine.onClick:Add(this.refineClick);
    btn_unload.onClick:Add(this.unloadClick);
    btn_switch.onClick:Add(this.onSwitch)
    btn_replace.onClick:Add(this.replaceClick);
    btn_buy.onClick:Add(this.buyClick);
    btn_upGrade.onClick:Add(this.GoGrade)
    this.btnSuitTipInfo.onClick:Add(this.ClickSuitTipInfo)
end

function UIEquipInfo.onSwitch()

    if this.last_click_switch_suit ~= nil and UnityEngineTime.realtimeSinceStartup - this.last_click_switch_suit < 5 then
        UISysTips.AddMsg(getLanguage("EquipSwitchTips1")) --todo
        return
    end
    this.last_click_switch_suit = logicMgr.EquipManager.getLastSendSwitchTime()
    local pId = tonumber(this.curShowHeroData.partnerId)
    local equipIndex = this.curEquipData.part -1
    local equipCfg = dataTable.getDataTableByStringId("t_equip",this.curEquipData.itemModelId)
    local newEquipSuitId = equipCfg.f_SuitChange or 1
    equipHandler.sendSwitchSuit(pId,newEquipSuitId,equipIndex)

end

function UIEquipInfo.removeEvent()
    bgclose.onClick:Clear();
    btn_refine.onClick:Clear();
    btn_unload.onClick:Clear();
    btn_switch.onClick:Clear()
    btn_replace.onClick:Clear();
    btn_buy.onClick:Clear();
    btn_upGrade.onClick:Clear()
    this.btnSuitTipInfo.onClick:Clear()
end

function UIEquipInfo.LocalListenEvent()
    ListenEvent(Config.EventType.Fresh_Refine, this.initUI);
    ListenEvent(Config.EventType.Fresh_Suit_Switch,this.initUI)
    ListenEvent(Config.EventType.TouchAnyKey,this.TouchAnyKey)
end

function UIEquipInfo.LocalCloseEvent()
    CloseEvent(Config.EventType.Fresh_Refine, this.initUI);
    CloseEvent(Config.EventType.Fresh_Suit_Switch,this.initUI)
    CloseEvent(Config.EventType.TouchAnyKey,this.TouchAnyKey)
    logicMgr.FuncOpenManager.removeStatusCtr(PanelNames.UIEquipInfo);
end

function UIEquipInfo.GoGrade()
    if this.btn_upGrade.grayed then
        UISysTips.AddMsg(getLanguage("EquipBreakTips8"))
        return
    end
    closeUI(PanelNames.UIEquipInfo)
    showUI(PanelNames.UIEquipBreak,curShowHeroData,curEquipData)
end

function UIEquipInfo.OnDestroy()
    this.removeEvent();
end

function UIEquipInfo.OnEnable()
    this.LocalListenEvent();
  
end

function UIEquipInfo.OnDisable()
    this.LocalCloseEvent();
    UIRedDots.removeViewEvent(PanelNames.UIEquipInfo)
end

function UIEquipInfo.initUI()
    btn_unload.visible = false;
    btn_replace.visible = false;
    btn_refine.visible = false;
    btn_buy.visible = false;
    nodeCost.visible = false;
    btn_switch.visible = false
    if panelType ~= nil and panelType == panelEnum.shop then
        btn_buy.visible = true;
        nodeCost.visible = true;
        -- 商城-单价显示处理
        this.ShopPriceShowLogic()
        local heroList = logicMgr.EquipManager.GetNeedEquipHeroListByData(curEquipData);
        if #heroList > 0 then
            this.recommend.selectedIndex = 1;
            this.recommendList:RemoveChildrenToPool();
            local HeadRectDrawItem = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
            if HeadRectDrawItem ~= nil then
                for k, v in pairs(heroList) do
                    local itemObj = this.recommendList:AddItemFromPool();
                    HeadRectDrawItem.initData(itemObj, v);
                    itemObj.onClick:Clear();
                end
            end
        end
    elseif curEquipData.itemId then
        curEquipData = logicMgr.EquipManager.getEquipbyId(curEquipData.itemId);
        btn_unload.visible = curShowHeroData ~= nil;
        btn_replace.visible = curShowHeroData ~= nil;
        local tar = dataTable.getDataTableByStringId("t_equip",curEquipData.itemModelId,"f_QualityUpTarget")
        if tar ~= 0 and curShowHeroData ~= nil then
            this.breakctrl.selectedIndex = 1
            UIRedDots.addViewListen(PanelNames.UIEquipInfo,gameObject.gameObjectName.."btn_upGrade",btn_upGrade,Config.RedDotsType.EquipBreak,nil, curEquipData);
        else
            this.breakctrl.selectedIndex = 0
        end

        --todo
        if curEquipData then
            local gray = curEquipData.upTargetId and curEquipData.upTargetId ~= 0
            this.btn_upGrade.grayed = not gray
        end


        if curEquipData ~= nil then
            partID = curEquipData["part"];
            local maxRef = logicMgr.EquipManager.GetMaxRefineLevel(curEquipData.itemModelId)
            btn_refine.visible = maxRef > 0
            if   tonumber(curEquipData["curRfLevel"]) < maxRef then
                logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UIEquipInfo,Config.FuncOpenType.EquipRefine, btn_refine.name,btn_refine);
                btn_refine.grayed = false
                UIRedDots.addViewListen(PanelNames.UIEquipInfo,gameObject.gameObjectName.."btn_refine",btn_refine,Config.RedDotsType.Allrefine,nil, curEquipData);
            else
                if maxRef > 0 then
                    btn_refine.grayed = true
                end
            end
        end
    end
    this.ctrlStateEquip.selectedIndex = 0
    --从背包进显示
    local showChange
    if this.panelType == this.panelEnum.UICharactorInfoHeroEquip then
        showChange = true
        this.ctrlStateEquip.selectedIndex = 2
    else
        if this.panelType == this.panelEnum.Bag then
            this.ctrlStateEquip.selectedIndex = 1
        else
            if this.panelType == this.panelEnum.shop then
                this.ctrlStateEquip.selectedIndex = 4
            end
        end
    end

    if curEquipData ~= nil then
        if curEquipData.itemId == nil then
        end
        local item = logicMgr.CtrlManager.GetCtrl(PanelNames.Item)
        item.initData(this.equipItem,curEquipData)
        item.DisableClick(this.equipItem)

        local equipCfg = dataTable.getDataTableByStringId("t_equip",curEquipData.itemModelId)
        equipName.text = curEquipData["name"];
        local prefix = EnumConst.StarType[curEquipData.quality]..getLanguage("EquipJobType" .. curEquipData.heroType .. curEquipData.part)
        part.text =  prefix
        partIcon.url =  EnumConst.AtlasPath.ICONAtlas..EnumConst.HeroTypeIcon[equipCfg.f_EquipHeroType]
        equipDes.text = curEquipData["desc"]
        local rare = getLanguage("EquipQuality" .. curEquipData["quality"]);
        local tempNum = 1
        --[[if this.ctrlStateEquip.selectedIndex==2 or this.ctrlStateEquip.selectedIndex==3 then
            tempNum = logicMgr.HeroPotentialMgr.EquipCrease()[curEquipData["quality"]*10] or 1
        end--]]
        attack.text = Mathf.Round(EquipManager.GetPower(curEquipData)*tempNum)
        curEquipData.power=EquipManager.GetPower(curEquipData);
        local refineLev = nil
        if curEquipData["curRfLevel"] and tonumber(curEquipData["curRfLevel"]) ~= 0 then
            refineLev = "+"..tostring(curEquipData["curRfLevel"]);
        else
            refineLev = "";
        end
        this.initEquipAttr();

        if curEquipData["suit"] == nil or tonumber(curEquipData["suit"]) == 0 then
            suit.visible = false;
            this.ctrlSuit.selectedIndex = 1
        else
            local suitCount = 0
            local minQ = curEquipData.quality
            local highQ = curEquipData.quality
            -- 是否穿戴
            if curShowHeroData and curShowHeroData.partnerId then
                suitCount,this.twoSuit,this.fourSuit,minQ,highQ = logicMgr.EquipManager.GetActiveSuitByEquipId(curShowHeroData.partnerId,curEquipData.itemModelId)
            end

            local suitCfg = logicMgr.EquipManager.GetSuitCfgByEquipId(curEquipData.itemModelId)
            if suitCfg then
                local minQCfg = dataTable.getDataTableByMultiId("t_equipsuit",curEquipData.suit,curEquipData.heroType,minQ)
                if minQCfg.f_EquipSuit >= 1 then
                    local url = EnumConst.AtlasPath.ICONAtlas.."suit"..minQCfg.f_EquipSuit
                    suitIcon.url = url
                    suitIcon2.url = url
                    btn_switch.visible = true
                    if showChange  then
                        this.ctrlStateEquip.selectedIndex = 3
                    end
                    this.ctrlSuit.selectedIndex = 0
                else
                    suitIcon.url = ""
                    suitIcon2.url = ""
                    if showChange  then
                        this.ctrlStateEquip.selectedIndex = 2
                    end
                    this.ctrlSuit.selectedIndex = 1
                end

                local suitData1 = this.twoSuit and this.twoSuit or suitCfg
                local suitData2 = this.fourSuit and this.fourSuit or suitCfg

                this.twoSuitDataList = decodeJsonStrToTabel(suitData1.f_EquipSuitValue1)
                local num = table.getn(this.twoSuitDataList)
                this.twoList.numItems = num
                this.twoList:ResizeToFit(num,0)

                this.fourSuitDataList = decodeJsonStrToTabel(suitData2.f_EquipSuitValue2)
                num = table.getn(this.fourSuitDataList)
                this.fourList.numItems = num
                this.fourList:ResizeToFit(num,0)
                this.initSuitAttr(suitCount,suitCfg, this.twoSuit ,this.fourSuit,minQ,highQ)
                suit.visible = true;
            else
                suit.visible = false;
                if showChange  then
                    this.ctrlStateEquip.selectedIndex = 2
                end
                this.ctrlSuit.selectedIndex = 1
            end
        end
    end
end

--- 商城-单价显示处理
function UIEquipInfo.ShopPriceShowLogic()
    if panelType ~= nil and panelType == panelEnum.shop then
        nodeCostIcon.url = "ui://ItemAtlas/".. curEquipData["moneyIcon"]
        local hadNum = logicMgr.ItemManager.getBagNumByTableID(curEquipData["monyType"])
        local tips = getNumString(curEquipData["price"])
        if tonumber(hadNum) < tonumber(curEquipData["price"]) then
            tips = string.format("<color=red>%s</color>", tips)
        end
        nodeCostTxt.text = tips
    end
end

--装备属性(基础属性，随机属性（待整理，目前没值）)
function UIEquipInfo.initEquipAttr()
    baseAttrData = decodeJsonStrToTabel(curEquipData["baseAttr"]);
    if baseAttrData then
        local num = #baseAttrData;
        if this.attrlist then
            this.attrlist.numItems = num
            this.attrlist:ResizeToFit(num,0)
        end
    end
end

--- 属性类型 == 2时，表示百分比属性。保留3位小数，通过百分比显示
--- @param attrType number 属性类型
--- @param attrValue number 属性值
--- @return string 格式化文本
--- @private
local function _formatPercentAttr(attrType, attrValue)
    if attrType == 2 then
        return string.format("%0.1f%%", tostring(attrValue / 100));
    else
        return attrValue;
    end
end

function UIEquipInfo.RenderAttr(idx, obj)
    local baseAttr = obj
    local idx = idx + 1
    local attrId = baseAttrData[idx][1]
    local tempNum = 1
    if this.ctrlStateEquip.selectedIndex==2 or this.ctrlStateEquip.selectedIndex==3 then
        if logicMgr.HeroPotentialMgr.IsAtkHpDef(attrId) then
            tempNum = logicMgr.HeroPotentialMgr.EquipCrease()[curEquipData["quality"]*10] or 1
        end
    end
    local attrValue = Mathf.Round(baseAttrData[idx][2]*tempNum)
    local attrName = getLanguage(string.format(Config.LangAttribute, attrId));
    local baseAttrName = baseAttr:GetChild("name");
    local baseAttrValue = baseAttr:GetChild("refine");
    local baseAttrRefine = baseAttr:GetChild("value");

    local attrType = 1;
    if G.dataTable["t_attributelibrary"] and G.dataTable["t_attributelibrary"][tostring(attrId)] then
        local attrConfig = G.dataTable["t_attributelibrary"][tostring(attrId)];
        attrType = attrConfig["f_AttributeType"];
    end

    if attrValue > 0 then
        baseAttrName.text = attrName .. " "
        baseAttrValue.text = EquipManager.formatAttr(attrId, attrValue);
        baseAttrRefine.text = "";
        local curRfLevel = curEquipData.curRfLevel
        if curRfLevel ~= nil and  curRfLevel > 0 then
            local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine",curEquipData.itemModelId,curRfLevel)
            baseAttrRefine.text = "+"..EquipManager.formatAttr(attrId,refineCfg.f_EquipRefineAttribute[idx][2])
        end
    else
        baseAttr.visible = false
    end
end

local lightColor = "#CFFFBE"
local grayColor = "#999999"

function UIEquipInfo.RenderSuitAttrBase(itemObj,data,isFour)
    local desText = itemObj:GetChild("Text_Des")
    local mgr = logicMgr.EquipManager
    local str = mgr.GetAttrName(data[1]).."  "..mgr.GetAttrValue(data[1],data[2])
    local color = this.twoSuit and lightColor or grayColor
    if isFour then
        color = this.fourSuit and lightColor or grayColor
    end
    desText.text = string.TextColor(str,color)
end

function UIEquipInfo.RenderTwoSuitAttr(index, itemObj)
    if this.twoSuitDataList then
        local idx = index + 1
        local data = this.twoSuitDataList[idx]
        UIEquipInfo.RenderSuitAttrBase(itemObj,data)
    end
end

function UIEquipInfo.RenderTwoSuitAttr2(index, itemObj)
    if this.fourSuitDataList then
        local idx = index + 1
        local data = this.fourSuitDataList[idx]
        UIEquipInfo.RenderSuitAttrBase(itemObj,data,true)
    end
end

function UIEquipInfo.RefreshSuitAttr(suitName,result_num,suitData,txtColor,color)
    suitName.text = string.TextColor(getLanguage(suitData.f_EquipSuitName),color)
    result_num.text = string.TextColor(txtColor,color)
end



--套装属性
function UIEquipInfo.initSuitAttr(totalNum,curSuit, twoSuit , fourSuit,minQuality,maxQuality)
    local two = math.min(totalNum,2)

    local txtColor1 = string.format("%s/2",two)
    local txtColor2 = string.format("%s/4",totalNum)

    if twoSuit then
        this.UIEquipInfo.RefreshSuitAttr(this.suitName,this.result_num1,twoSuit,txtColor1,lightColor)
    else
        this.UIEquipInfo.RefreshSuitAttr(this.suitName,this.result_num1,curSuit,txtColor2,grayColor)
    end

    if fourSuit then
        this.UIEquipInfo.RefreshSuitAttr(this.suitName2,this.result_num2,fourSuit,txtColor2,lightColor)
    else
        this.UIEquipInfo.RefreshSuitAttr(this.suitName2,this.result_num2,curSuit,txtColor2,grayColor)
    end
end

function UIEquipInfo.refineClick()
    if not logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.EquipRefine, true,btn_refine) then
        return ;
    end
    if curEquipData == nil then
        ---穿装备 打开装备列表
        showUI(PanelNames.UIEquipRefine, curShowHeroData, nil);
    elseif curEquipData ~= nil then
        ---脱装备 打开装备信息
        if btn_refine.grayed then
            UISysTips.AddMsg(getLanguage("ErrorCode_804"))--精炼等级最大了
            return
        end

        showUI(PanelNames.UIEquipRefine, curShowHeroData, curEquipData);
    end
    closeUI(PanelNames.UIEquipInfo);
end

function UIEquipInfo.unloadClick()
    if this.partID == EnumConst.EquipPartEnum.FRAGMENT then
        --卸载奇异碎片
        local _fragmentInfo = StrangeFragmentManager.GetFragmentInfoByPartnerId(this.curShowHeroData.partnerId)
        weaponHandler.ReqFragmentDemount(this.curShowHeroData.partnerId,_fragmentInfo.itemId)
    else
        equipHandler.sendUnWear(curShowHeroData.partnerId,partID);
    end
    local _heroType = G.dataTable["t_hero"][tostring(curShowHeroData.partnerModelId)]["f_HeroType"]
    if _heroType then
        AudioManager.TryPlaySoundByWear(_heroType,false)
    end
    closeUI(PanelNames.UIEquipInfo);
end

--装备替换
function UIEquipInfo.replaceClick()
    if curEquipData == nil then
        ---穿装备 打开装备列表
        showUI(PanelNames.UIEquipList, curShowHeroData, nil);
    elseif curEquipData ~= nil then
        ---脱装备 打开装备信息
        showUI(PanelNames.UIEquipList, curShowHeroData, curEquipData);
    end
    closeUI(PanelNames.UIEquipInfo);
end

--商店购买装备
function UIEquipInfo.buyClick()
    local hadGoldNum = logicMgr.ItemManager.getBagNumByTableID(curEquipData["monyType"]);
    local itemName = G.dataTable["t_item"][tostring(curEquipData["monyType"])].f_ItemName
    if tonumber(hadGoldNum) >= tonumber(curEquipData["price"]) then
        if curEquipData["specialBuyType"] ~= nil and curEquipData["specialBuyType"] == 1 then
            --print("主线随机事件购买");
            DungeonRandomEventHandler.sendDungeonRandomEventShopBuy(curEquipData, 1);
        elseif curEquipData["LongJourneyHellShop"] == 1 then
            if this.func ~= nil then
                this.func();
            end
        else
            shopHandler.reqBuyShopItem(curEquipData);
        end
    else
        UISysTips.AddMsg(string.format(getLanguage("Character_Tips19"), getLanguage(itemName)))
    end

    closeUI(PanelNames.UIEquipInfo);
end

function UIEquipInfo.TouchAnyKey()
end

function UIEquipInfo.ClickSuitTipInfo()
    if this.ctrlSuitInfo.selectedIndex == 1 then
        this.ctrlSuitInfo.selectedIndex = 0
        return
    end
    this.ctrlSuitInfo.selectedIndex = 1
    --未穿戴
    if not curShowHeroData then
        local str = string.TextColor(getLanguage("Sys_Quality"..curEquipData.quality),Config.EquipQualityColor[curEquipData.quality])
        this.suitTipText.text = string.format(getLanguage("Sys_EquipSuit_Tip1"),str)
        return
    end

    local swearEquips = logicMgr.EquipManager.getHeroEquipList(curShowHeroData.partnerId,true)
    local highQ = dataTable.getGlobalInt(240)--curEquipData.quality
    local minQ = curEquipData.quality
    for key, value in pairs(swearEquips) do
        if value.suit == curEquipData.suit then
            if minQ > value.quality then
                minQ = value.quality
            end
        end
    end
    if minQ < highQ then
        local str = string.TextColor(getLanguage("Sys_Quality"..minQ),Config.EquipQualityColor[minQ])
        this.suitTipText.text = string.format(getLanguage("Sys_EquipSuit_Tip2"),str)
        return
    end
    if minQ == highQ then
        local str = string.TextColor(getLanguage("Sys_Quality"..highQ),Config.EquipQualityColor[highQ])
        this.suitTipText.text = string.format(getLanguage("Sys_EquipSuit_Tip3"),str)
    end
end

function UIEquipInfo.clickClose()
    closeUI(PanelNames.UIEquipInfo);
end



return UIEquipInfo;